import java.util.Scanner;
public class C1429 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt(),n = sc.nextInt();
		int[][] a = new int[m][n];
		for(int i =0;i<m;i++)
			for(int j = 0;j<n;j++) 
				a[i][j] = sc.nextInt();
		int ii = sc.nextInt(),jj = sc.nextInt();
		char fang = sc.next().charAt(0);
		int step = sc.nextInt();
		int f = fang=='U'?400000:fang=='R'?400001:fang=='D'?400002:400003;
		for(int i = 0;i<step;i++) {
			if(a[ii][jj]==1) f++;
			else f--;
			a[ii][jj]=a[ii][jj]==1?0:1;
			if(f%4==0) ii--;
			if(f%4==1) jj++;
			if(f%4==2) ii++;
			if(f%4==3) jj--;
		}
		System.out.println(ii+" "+jj);
	}

}
